package cn.wolfcode.luowowo.website.web.controller;

import cn.wolfcode.luowowo.article.domain.Flight;
import cn.wolfcode.luowowo.article.query.FlightQuery;
import cn.wolfcode.luowowo.article.service.IFlightService;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import cn.wolfcode.luowowo.search.query.FlightQueryObject;
import cn.wolfcode.luowowo.search.service.IFlightEsService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.xml.crypto.Data;
import java.util.List;

@Controller
@RequestMapping("/flight")
public class FlightController {
    @Reference
    private IFlightEsService flightEsService;
    @Reference
    private IFlightService flightService;
    @RequestMapping("")
    public String search(Model model){
        /*Page hotFlights = flightEsService.query(qo);
        for (Object hotFlight : hotFlights) {
            System.out.println(hotFlight.toString());
        }
        model.addAttribute("hotFlights",hotFlights);
*/
        List<Flight> hotFlights = flightService.query();
        model.addAttribute("hotFlights",hotFlights);
        return "flight/index";
    }
    // http://localhost:8888/flight/search?depTime=2020-04-01
    @RequestMapping("/search")
    private String searchByDepTime(Model model,FlightQueryObject qo){
        Page list = flightEsService.query(qo);
        //List<Flight> list = flightService.query();
        model.addAttribute("list",list);

        return "flight/flightsTpl";
    }
}
